//
//  CityChooserCell.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/12/20.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "CityChooserCell.h"

@interface CityChooserCell ()

/// viewModle
@property (nonatomic, readwrite, strong) CityChooserCellModel *viewModel;

/// IBOutlet
@property (weak, nonatomic) IBOutlet UILabel* cityLabel;
@property (weak, nonatomic) IBOutlet UIImageView* chooserImgView;

@end

@implementation CityChooserCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

#pragma mark - bind data
- (void)bindViewModel:(CityChooserCellModel *)viewModel
{
    self.viewModel = viewModel;
    
    @weakify(self);
    
    self.backgroundColor = self.viewModel.bColor;
    
    self.cityLabel.text = self.viewModel.cityName;
    
    [[RACObserve(self.viewModel, isChoose) takeUntil:[self rac_prepareForReuseSignal]] subscribeNext:^(id x)
    {
        @strongify(self);
        
        BOOL isChoose = [x boolValue];
        
        self.chooserImgView.hidden = !isChoose;
    }];
    
    [[RACObserve(self.viewModel, isOn) takeUntil:[self rac_prepareForReuseSignal]] subscribeNext:^(id x)
     {
         @strongify(self);
         
         BOOL isChoose = [x boolValue];
         
         NSLog(@"IsChoose : %@", isChoose?@"YES" : @"NO");
         
         self.cityLabel.textColor = isChoose ? UIColorHex(#008f58) : UIColorHex(#000000);
     }];
}

@end

